﻿
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using Model;


namespace MsDAL
{
    public partial class Psn0a00DAL : Psn0a00Base
    {
        public SqlApp AddOrUpdateSetting(Psn0a01 model)
        {
            string strsql = @"
                IF exists(SELECT 1 FROM Psn0a01 WHERE comcode = @comcode AND item = @item)
                    UPDATE Psn0a01 SET value1 =@value1 WHERE comcode = @comcode AND item = @item
                ELSE
                    INSERT INTO Psn0a01(comcode,item,value1)
                    SELECT @comcode, @item, @value1
                    WHERE NOT EXISTS(SELECT 1 FROM Psn0a01 WHERE comcode = @comcode AND item = @item); ";

            SqlParameter[] parameters = {
				new SqlParameter("@comcode",SqlDbType.NVarChar),
				new SqlParameter("@item",SqlDbType.NVarChar),
				new SqlParameter("@value1",SqlDbType.NVarChar)
				};
            parameters[0].Value = model.Comcode;
            parameters[1].Value = model.Item;
            parameters[2].Value = model.Value1;

            return new SqlApp(strsql, new ArrayList(parameters), false, "数据保存失败！");
        }
    }
}
